/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.demo.jackson.ser;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 请使用 {@link com.fasterxml.jackson.annotation.JsonFormat}代替
 * <p/>
 *
 * @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8"), timezone 需要指定
 * @author: vacoor
 * @deprecated
 */
@Deprecated
public class DateSerializer extends JsonSerializer<Date> {
    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        String dt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        /*-
        writeString 会自动加上: ""
        writeRaw 只将给定内容写入,不做任何操作
         */
        gen.writeString(dt);
    }
}
